package com.zhiyou.homework.controller;

import com.zhiyou.common.pojo.Result;
import com.zhiyou.common.pojo.StateCode;
import com.zhiyou.homework.pojo.Exam;
import com.zhiyou.homework.pojo.Grade;
import com.zhiyou.homework.service.ExamService;
import com.zhiyou.homework.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("/exam")
public class ExamScoreController {

    @Autowired
    private TeacherService teacherService;

    @Autowired
    private ExamService examService;


    /**
     * 打开成绩管理首页
     * 展示当前教师所教全部班级的下拉列表
     * 以及展示默认第一个班级的全部考试名称
     * 接口测试OK
     * TODO 原型图展示的是xxx成绩单,这里数据存储查出都是xxx考试
     */
    @GetMapping("/{tid}")
    public Result findAllExam(@PathVariable Integer tid) {
        // 查询老师所教所有班级,且按班级编号降序
        Map<String, TreeSet> gradeCourseMap = teacherService.findGradeAndCourseByTeacherId(tid);
        TreeSet gradeSet = gradeCourseMap.get("grade");
        // 获得第一个班级
        Grade firstGrade = (Grade)gradeSet.first();
        // 获得该班所有考试信息
        List<Exam> exams = examService.findAllByGid(firstGrade.getGid());
        Map<String, Collection> map = new HashMap<>();
        map.put("grade",gradeSet);
        map.put("exam",exams);
        return new Result(true, StateCode.OK,"查询全部考试成功",map);
    }

}
